package se.hh.service;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import se.hh.lab.dao.UserDao;
import se.hh.lab.dao.impl.UserDaoImpl;
import se.hh.lab.domain.Login;
import se.hh.lab.domain.User;

public class UserPersonalInfo extends HttpServlet
{

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		HttpSession session=request.getSession();
		Login login=(Login) session.getAttribute("userlogin");
		
		if(null==login)
		{
			response.sendRedirect("user_login.jsp");
			return;
		}
		else
		{
			String userID=login.getUserID();
			User user=new User();
			user.setUserID(userID);
			UserDao userDao=new UserDaoImpl();
			ArrayList<User> list=userDao.getUser(user);
			for(int i=0;i<list.size();i++)
			{
				user.setUserID(list.get(i).getUserID());
				user.setFirstname(list.get(i).getFirstname());
				user.setLastname(list.get(i).getLastname());
				user.setAge(list.get(i).getAge());
				user.setDate(list.get(i).getDate());
				user.setEmail(list.get(i).getEmail());
				user.setGender(list.get(i).getGender());
				user.setPhone(list.get(i).getPhone());
				user.setRemark(list.get(i).getRemark());				
			}
			session.setAttribute("user", user);
			request.getRequestDispatcher("user_personalInfo.jsp").forward(request, response);
		}		
	}


	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		this.doGet(request, response);
	}

}
